<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改帮助文档</title>
<%@ include file="/view/common/tags.jsp"%>
	<link rel="stylesheet" href="${sysManagerV1}/js/kindeditor/themes/default/default.css" type="text/css"/>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" id="saveAndUpdateFrom" target="_parent" action=""  enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-xs-2 text-right">文档类型：</label>
	            <div class="col-xs-3">
	            	<sk:select cssClass="form-control" name="documentType" id="documentType" value="${checkDocumentType}">
	                	<option value="">请选择</option>
						<option value="10">注册协议</option>
						<option value="20">订单协议</option>
	            	</sk:select>
	            </div>
				<label class="col-xs-2 text-right">文档标题：</label>
	            <div class="col-xs-3">
	            	<input id="documentTitle" name="documentTitle" value="" class="form-control" placeholder="请输入文档标题">
	            </div>
            </div>
            <div class="form-group" >
                <label class="col-xs-2 text-right">排序编号：</label>
                <div class="col-xs-3">
                    <input id="orderByNo" name="orderByNo" value="" class="form-control">
                </div>
                <label class="col-xs-2 text-right">是否启用：</label>
                <div class="col-xs-3">
                    <td colspan="2">
                        <label for="port"><input id="yes" name="openFlag" type="radio"  value="1"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label for="no"><input id="no" name="openFlag" type="radio" value="0"/>&nbsp;否</label>
                    </td>
                </div>
            </div>
			<div class="form-group">
				<div class="col-xs-12" style="padding-left: 30px;">
					<textarea id="documentContent" name="documentContent" style="width:680px;height:380px;border:#ccc solid 1px;text-indent:3px;padding-top:3px;"/></textarea>
				</div>
			</div>
			<input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>">
			<input type="hidden" id="isReCommit" value="0">
		</sk:form>	
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script type="text/javascript" charset="UTF-8" src="${sysManagerV1}/js/kindeditor/kindeditor-min.js"></script>
    <script type="text/javascript" charset="gbk" src="${sysManagerV1}/js/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript">
$(function(){
    // 初始化
    KindEditor.ready(function(K) {
        ke = K.create('textarea[name="documentContent"]', {
            resizeType : 0,
            urlType : 'domain',
            uploadJson : '${sysManagerV1}/keUploadImg/uploadImg',
            items : [
             'undo', 'redo', '|', 'selectall', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|',
             'quickformat', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor',  'hilitecolor', 'bold', 
             'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'link', 'unlink', 'image', 'emoticons', 'pagebreak', 
             '|', 'justifyleft', 'justifycenter', 
             'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'clearhtml', '|', 'preview', 'source', 'about' 
            ]
        });
    });
    
    var rowId = $("#rowId").val();
    if(rowId >= 0){
        $.ajax({
            url: "${sysManagerV1}/pubgBaseHelpDocument/getBaseHelpDocumentInfo",
            type: "post",
            cache: false,
            data:{"rowId":rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                $("#documentType").val(data.documentType);
                $("#documentTitle").val(data.documentTitle);
                $("#orderByNo").val(data.orderByNo);
                if(data.openFlag == 1){
                    $("#yes").attr("checked","true");
                    $("#no").removeAttr("checked");
                } else {
                    $("#yes").removeAttr("checked");
                    $("#no").attr("checked","true");
                }
                $("#documentContent").val(data.documentContent);
            }
        });
    }
})

var err = {'1':'添加','2':'修改'};
var action = {'1':'/save','2':'/update'};
function add(){
    var rowId = $('#rowId').val();
    var i;
    if (!CheckUtil.isNotNull(rowId) || rowId == 0) {
        i = 1;//添加
    } else {
        i = 2;//修改
    }
    var documentType = $('#documentType').val();
    if (!CheckUtil.isNotNull(documentType)) {
        layer.msg("请选择帮助文档类型!");
        return;
    }
    
    var documentTitle = $('#documentTitle').val();
    if (!CheckUtil.isNotNull(documentTitle)) {
        layer.msg("请填写文档标题!");
        return;
    }
    //参数一系列校验
    var openFlag =$('input:radio[name="openFlag"]:checked').val();
    if (!CheckUtil.isNotNull(openFlag)) {
        layer.msg("请选择是否开启!");
        return;
    }
    var orderByNo = $('#orderByNo').val();
    if (!CheckUtil.isNotNull(orderByNo) || !CheckUtil.isInt(orderByNo, "+") || orderByNo == 0) {
        layer.msg("请输入正确的排序编号!");
        return;
    }
    
    //富编辑框内容
    ke.sync();
  
    //loading层
    var index = layer.load(0, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    
    $.ajax({
        url: "${sysManagerV1}/pubgBaseHelpDocument" + action[i],
        type: "post",
        cache: false,
        data: new FormData($("#saveAndUpdateFrom")[0]),
        dataType:"json",
        processData: false,
        contentType: false,
        async:false,
        success: function(data) {
            layer.close(index);
            if(data.code == 0){
                parent.layer.msg("添加成功！");
            } else if(data.code == 1){
                parent.layer.msg("修改成功！");
            } else if(data.code == "-2"){
                parent.window.location.href="${sysManagerV1}/";
            } else {
                parent.layer.msg(data.message);
            }
            if(data.code >= 0){
                parent.findData();
                parent.layer.close(parent.tableIndex);
            }
        }
    });
}

</script>
</html>